Ext.onReady(function() {
			var bar = new Ext.Toolbar([{
						text : "添加管理员",
						icon : '../../resource/add.gif',
						handler : addAdmin
					}, {
						text : "删除",
						icon : '../../resource/delete.png',
						handler : function() {
							Ext.MessageBox.buttonText.yes = '确定';
							Ext.MessageBox.buttonText.no = '取消';
							var selectModel = grid.getSelectionModel();
							var selectRecord = selectModel.getSelections();
							if (selectRecord.length == 0) {
								Ext.Msg.alert('', '请选择至少一项');
								return;
							}
							Ext.Msg.show({
										msg : '确定删除所选项吗？删除后将无法恢复',
										buttons : Ext.Msg.YESNO,
										fn : function(bt) {
											if (bt == 'yes') {
												deleteAdmin(selectRecord);
											};
										},
										icon : Ext.MessageBox.QUESTION
									});
						}
					}

			]);
	var cb=new Ext.grid.CheckboxSelectionModel();
	var store = new Ext.data.JsonStore({
        root: 'data',
        totalProperty: 'totalcount',
        fields: [
        	'dbID','userID','name','type'
        ],
        proxy: new Ext.data.HttpProxy({
            url: 'GetAdminAction'
        }),
        autoLoad:{params:{start:0,limit:50}}
    });
    var edit=new Ext.form.TextField({
               allowBlank: false
    });
	var grid=new Ext.grid.EditorGridPanel({
		columnLines: true,
		region:'center',
		loadMask:true,
		listeners:
		{
			afteredit:updateAdmin
		},
		tbar:[
			bar,
			new Ext.PagingToolbar({
				store:store,
				pageSize:50,
				displayInfo: true,
				displayMsg:'第 {0} 条到 {1} 条,一共 {2} 条',
				emptyMsg:'没有记录'
			})
		],
		stripeRows:true,
		autoScroll:true,
		applyTo:'admin_grid',
		frame:true,
		sm:cb,
		store:store,
		columns:[
		new Ext.grid.RowNumberer({
			header:'行号',
			width:40
		}),
		cb,
		{header:"数据库编号",width:200,dataIndex:'dbID',align:'center',sortable:true},
		{header:"编号",width:200,dataIndex:'userID',align:'center',editor:edit,sortable:true},
		{header:"姓名",width:200,dataIndex:'name',align:'center',editor:edit,sortable:true}
		]
	});
	var adminForm=new Ext.FormPanel({
		border:false,
		labelAlign:'right',
		frame:true,
		buttonAlign:'center',
		id:'addAdminForm',
		name:'addAdminForm',
		items:[
		{
			xtype:'textfield',
			width:150,
			allowBlank:false,
			name:'userID',
			fieldLabel:'学号'
		},
		{
			xtype:'textfield',
			width:150,
			name:'name',
			fieldLabel:'姓名'
		}
		],
	buttons:[
		new Ext.Button({
			text:'提交',
			handler:submitAdmin
		}),
		new Ext.Button({
			text:'重置',
			handler:function(){adminForm.form.reset();}
		})
	]
	});
	new Ext.Viewport({
		layout:'border',
		items:[
			grid
		]
	});
	var adminWin=new Ext.Window({
		plain:true,
		width:300,
		height:130,
		closeAction:'hide',
		listeners:
		{
			'beforehide':function(){store.reload();}
		},
		bodyStyle:'padding:5px',
		modal:true,
		closable:true,
		animCollapse:true,
		resizable:false,
		items:[adminForm
		]
	});
	function addAdmin()
	{
		adminForm.form.reset();
		adminForm.isAdd=true;
		adminWin.setTitle("添加管理员");
		adminWin.show();
	}
	function $value(id)
	{
		return document.getElementById(id).value;
	};
	function submitAdmin()
	{
		var data=getExtForm(adminForm);
		var json=Ext.util.JSON.encode(data);
		Ext.ajaxRequest(json,'addAdminAction');
	};
	function updateAdmin(e)
	{
		var data={};
		data['id']=e.record.get("dbID");
		data['field']=e.grid.getColumnModel().getDataIndex(e.column);
		data['value']=e.value;
		var json=Ext.util.JSON.encode(data);
		Ext.ajaxRequest(json,'updateAdminAction','更新成功','更新失败');

	}
	function deleteAdmin(record)
	{
		
		var idArray=new Array();
		for(var i=0;i<record.length;++i)
		{
			var r=record[i];
			idArray[i]=r.get('dbID');
		}
		var json=Ext.util.JSON.encode(idArray);
		Ext.ajaxRequest(json,'deleteAdminAction');
		store.reload();
	}
});